package com.imooc.test;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.junit.jupiter.api.Test;

/**
 * @author liansen
 * @create 06-01-2:13
 */
public class CaffeineTest2 {

    @Test
    public void caffeineTest() {
        Cache<String, Object> caffeine = Caffeine.newBuilder()
//                                                .maximumSize(1)
//                                                .expireAfterWrite(2, TimeUnit.SECONDS)
                                                .build();

        caffeine.put("name", "平安");
        caffeine.put("age", 27);
        caffeine.put("aa", "bb");

//        Thread.sleep(5000);

        Object name = caffeine.getIfPresent("name");
        System.out.println("name:" + name);

        Object age = caffeine.getIfPresent("age");
        System.out.println("age:" + age);

        Object aa = caffeine.getIfPresent("aa");
        System.out.println("aa:" + aa);
    }

}
